<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>watch监视属性</title>
    <script src="js/vue.js"></script>
</head>
<body>
<div id="root">
    <h2>今天天气很{{isHot ? '炎热' : "凉爽"}}</h2>
    <button @click="changeWeather">切换天气</button>
</div>
<script type="text/javascript">
    Vue.config.productionTip = false//禁止提示生产提示
    new Vue({
        el: "#root",
        data() {
            return {
                isHot: true
            }
        },
        methods: {
            changeWeather() {
            this.isHot=!this.isHot
            }
        },
        watch:{
            /*isHot完整写法*/
           /* isHot:{
                immediate:true,让监视的函数立即执行一次
                handler(newValue,oldValue){
                    console.log('isHot的值被修改,newValue,oldValue')
                }
            }*/
            /*isHot简写*/
            isHot(newValue,oldValue){
                console.log('isHot的值被修改,newValue,oldValue')
            }
        }
    })

</script>
</body>
</html>